home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 98 / Skunkware 98.iso / osr5 / sco / scripts / corename < prev    next >
Encoding:
Korn shell script  |  1997-08-26  |  1.3 KB  |  59 lines

  1. #!/bin/ksh
  2. # @(#) corename.ksh 1.2 96/05/21
  3. # 92/11/11 john h. dubois iii (john@armory.com)
  4. # 92/02/16 Added help option.
  5. # 92/02/22 Added cd to origdir to fix prob w/multiple relative paths.
  6. # 93/04/01 Added check for whether file exists.
  7. # 94/09/20 Use _fst if adb not available.
  8. # 96/01/20 Print 'empty' for 0-size corefiles.
  9. # 96/05/21 Let dir names be given.
  10.  
  11. # inspired by belal's equivalent utility
  12.  
  13. name=${0##*/}
  14. if [ "$1" = -h ]; then
  15.     print -- \
  16. "$name: print the names of executables that dumped core.
  17. Usage: $name [filename ...]
  18. If no filename is given, \"core\" is assumed.  If a directory name is given,
  19. the file \"core\" in that directory is searched for."
  20.     exit 0
  21. fi
  22.  
  23. type adb > /dev/null && adb=adb || adb=/etc/_fst
  24. type $adb > /dev/null || {
  25.     print -u2 "adb is not available."
  26.     exit 1
  27. }
  28.  
  29. [ $# = 0 ] && set core
  30. origdir=$PWD
  31. for i; do
  32.     cd $origdir
  33.     if [ -d "$i" ]; then
  34.     file=core
  35.     dir=$i/
  36.     i=$dir$file
  37.     else
  38.     file=${i##*/}
  39.     dir=${i%$file}
  40.     fi
  41.     [ -z "$dir" ] && dir=$origdir/
  42.     if [ ! -f $dir$file ]; then
  43.     print -u2 -- "$dir$file: No such file."
  44.     continue
  45.     fi
  46.     if [ ! -r $dir$file ]; then
  47.     print -u2 -- "$dir$file: Cannot open."
  48.     continue
  49.     fi
  50.     if [ ! -s $dir$file ]; then
  51.     print -u2 -- "$dir$file: (empty)"
  52.     continue
  53.     fi
  54.     cd $dir
  55.     set $($adb $file < /dev/null)
  56.     name=${4#??}
  57.     print -- "$i: ${name%??}"
  58. done
  59.